package com.mmlc.meimei.lichengkongjian;

import android.view.View;
import android.widget.TextView;

import com.androidnetframe.httputil.BaseRequestFilterLayer;
import com.androidnetframe.responsejavabean.RequestError;
import com.mmlc.inter.InterActivity;
import com.mmlc.network.filter.SaomaloginRequestFilter;
import com.mmlc.network.responsebean.GoodsDetailResponseBean;
import com.mmlc.utils.ToastUtils;

public class ComfirmLoginActivity extends InterActivity {


    @Override
    protected int initContentView() {
        return R.layout.activity_comfirm_login;
    }
    String code="";
    @Override
    protected void initView() {
        TextView name= (TextView) findViewById(R.id.name);
        code=getIntent().getStringExtra("login_code");
        if(code!=null){
            code=code.substring(code.indexOf("itryroom://")+"itryroom://".length());
            name.setText("您将登录设备:"+code);
        }
        findViewById(R.id.iv_back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        findViewById(R.id.commit).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SaomaloginRequestFilter saomaloginRequestFilter=new SaomaloginRequestFilter(ComfirmLoginActivity.this);
                if(code==null || code.equals("")){
                    ToastUtils.showToast("未获取到登录设备");
                    return;
                }
                saomaloginRequestFilter.requestBean.qrlogin=code;
                saomaloginRequestFilter.sendRequest(new BaseRequestFilterLayer.AccessResultFromFilter<GoodsDetailResponseBean>() {
                    @Override
                    public void onSuccess(GoodsDetailResponseBean result) {
                        ToastUtils.showToast(result.getMessage());
                        if(result.getCode()==0){
                            finish();
                        }
                    }
                    @Override
                    public void onFailed(View errorLayout, RequestError serverError, int failedType) {
                        ToastUtils.showToast(serverError.mess);
                    }
                });
            }
        });
    }
}
